<?php
// +--------------------------------------------------------------------------
// | ISDCE [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:086-010-57209502>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * [ 公共函数库 ]
 */
	function album_save_url($result,$music_urls){
		$m_mall_content = M("mall_content");
		
		$name_array = explode(".",$music_urls);
		$music_add_url = "http://p7j34hu3o.bkt.clouddn.com/".$name_array[0]."_3.mp3";
		$save_url_map['id'] = $result;
		$save_url_data['mp3'] = $music_add_url;
		$m_mall_content->where($save_url_map)->save($save_url_data);
		
	}
	
	#单曲详细信息  传入数组  歌曲id uid  song_detail
	function song_detail($song_str_list,$uid){
		$m_mall_content = M("mall_content");
		$m_mall_content_img = M("mall_content_img");
		
		foreach($song_str_list as $i=>$v){
			#参数 uid  歌曲id  
			#表  m_mall_content   m_mall_content_img
			
			$song_map_t['id'] = $song_str_list[$i];
			$song_map_t['status'] = 1;
			$song_str_data = $m_mall_content->where($song_map_t)->field("id,name,singer,value,mp3,foil_img")->find();
			if($song_str_data){
				$song_str_data['value'] = if_url($song_str_data['value']);
				$song_str_data['mp3'] = if_url($song_str_data['mp3']);
				$song_str_data['foil_img'] = if_url($song_str_data['foil_img']);
				#获取评论条数  m_cms_content_comments
				$song_str_data['pinglun_count'] = pinglun_count($song_str_list[$i]);
				#判断是否喜欢
				$song_str_data['if_like_song'] = if_like_song($song_str_list[$i],$uid);
				#判断是否是独家以及是否是超品
				$hq_dujia_array = if_hq_dujia($song_str_list[$i]);
				$song_str_data['if_hq'] = $hq_dujia_array['if_hq'];
				$song_str_data['if_dujia'] = $hq_dujia_array['if_dujia'];
				#获取四个路径
				$song_str_data['gedan_list'] = gedan_list($song_str_list[$i]);
				
				$xuanze_img_map['type'] = 1;					
				$xuanze_img_map['form_id'] = $song_str_list[$i];
				$xuanze_img_data = $m_mall_content_img->where($xuanze_img_map)->order("employ desc")->find();
				$song_str_data['img'] = if_url($xuanze_img_data['url']);
				$song_str_array[] = $song_str_data;
			}
			
			
		}
		return $song_str_array;
	}
	
	#四个品质
	function gedan_list($id){
		$m_mall_content_music = M("mall_content_music");
		$music_map['form_id'] = $id;
		$hq_list = $m_mall_content_music->where($music_map)->order("type asc")->field("type,url")->select();
		$song_data['hq_list'] = $hq_list;
		
		$gedan_list[] = $hq_list;
		
		return $gedan_list;
	}
	
	#判断是否喜欢单曲
	function if_like_song($id,$uid){
		$m_cms_collection = M("cms_collection");
		$if_like_map['type'] = 1;
		$if_like_map['form_id'] = $id;
		$if_like_map['uid'] = $uid;
		$if_like_data = $m_cms_collection->where($if_like_map)->find();
		if($if_like_data){
			$if_like = 1;
		}else{
			$if_like = 0;
		}
		#dump($if_like_data);die;
		return $if_like;
		
	}
	
	
	#判断是否喜欢单曲
	function if_like_user($id,$uid){
		$m_cms_collection = M("cms_collection");
		$if_like_map['type'] = 2;
		$if_like_map['form_id'] = $id;
		$if_like_map['uid'] = $uid;
		$if_like_data = $m_cms_collection->where($if_like_map)->find();
		if($if_like_data){
			$if_like = 1;
		}else{
			$if_like = 0;
		}
		#dump($if_like_data);die;
		return $if_like;
		
	}
	
	
	
	#评论条数
	function pinglun_count($id){
		$m_cms_content_comments = M("cms_content_comments");
		$pinglun_map['comments_id'] = $id;
		$pinglun_map['status'] = 1;
		$pinglun_count = $m_cms_content_comments->where($pinglun_map)->count();
		return $pinglun_count;
	}
	
	#判断独家以及高品质
	function if_hq_dujia($id){
		$m_mall_content = M("mall_content");
		$m_mall_content_music = M("mall_content_music");
		$m_common_user = M("common_user");
		
		#查询独家以及是否存在高品质
		$hq_map['type'] = array("egt",3);
		$hq_map['form_id'] = $id;
		$hq_map['url'] = array("neq",'');
		$hq_data = $m_mall_content_music->where($hq_map)->find();
		if($hq_data){
			$if_hq = 1;
		}else{
			$if_hq = 0;
		}
		$dujia_map['id'] = $id;
		$dujia_data = $m_mall_content->where($dujia_map)->field("uid")->find();
		#查询上传用户
		$d_map['id'] = $dujia_data['uid'];
		$d_data = $m_common_user->where($d_map)->field("agreement_id")->find();
		if($d_data['agreement_id'] >= 1){
			$if_dujia = 1;
		}else{
			$if_dujia = 0;
		}
		
		$array['if_hq'] = $if_hq;
		$array['if_dujia'] = $if_dujia;
		return $array;
	}
					
 
 
	function if_url($img){
		#判断是否是授权   授权的头像了路径不改变
		$user_img = substr($img,0,4);
		if($user_img != "http"){
			$url_img = "http://".$_SERVER['HTTP_HOST'].$img;
		}else{
			$url_img = $img;
		}
		return $url_img;
	}
	
	#根据当前票数，生成总的长度（进度条）
	function jindu_num($str){
		$count = strlen($str);
		$count = pow(10,$count);
		return  $count;
	}
	
	#获取所有音乐人
	function music_user(){
		$m_common_user = M("common_user");
		
		$map['group_id'] = 9;
		$map['status'] = 1;
		$list = $m_common_user->where($map)->field("id,nickname")->select();
		return $list;
	}
	
	
	#评论
	function comments($type,$comments_id=''){
		$m_cms_content_comments = M("cms_content_comments");
		$m_common_user = M("common_user");
		$m_mall_content = M("mall_content");
		
		#参数   1活动  2单曲  3专辑
		if($comments_id){
			$map['comments_id'] = $comments_id;
		}
		$map['type'] = $type;
		$map['status'] = array('in','1,2,3');
		$list = $m_cms_content_comments->where($map)->order("time desc")->select();
		
		foreach($list as $i=>$v){
			#用户名
			$u_map['id'] = $list[$i]['uid'];
			#$u_map['status'] = 1;
			$user_data = $m_common_user->where($u_map)->find();
			$list[$i]['nickname'] = $user_data['nickname'];
			#评论目标名称
			$song_map['id'] = $list[$i]['comments_id'];
			$song_data = $m_mall_content->where($song_map)->find();
			$list[$i]['title'] = $song_data['name'];
			
		}
		return $list;
	}
	function verifys_yanzheng($code){
		$verify = new \Think\Verify();
		$id = I("param.id")?I("param.id"):'';
		$results = $verify->check($code, $id);
		return $results;
	}
 
	   //  生成原始的二维码(生成图片文件)  
    function scerweima($url){  
		  require_once 'phpqrcode.php';  
			
		  $value = $url;                  //二维码内容  
			
		  $errorCorrectionLevel = 'L';    //容错级别   
		  $matrixPointSize = 5;           //生成图片大小
		  $datimes = date('Y-m-d',time());  
		  $lujing = mkdir('./uploads/ISNH5/'.$datimes);
		  $outfile = './uploads/ISNH5/'.$datimes.'/'.time().rand(1,999).'.png';  
		  QRcode::png($value,$outfile,$errorCorrectionLevel, $matrixPointSize, 2);
		  return $outfile;
    }
	
	function xiangce_add($value){
		 $pattern_img = '/<img (.+?)\/>/';
			 preg_match_all($pattern_img,$value,$matches_img);
			 
			 $pattern_src = '/src="(.+?)"/';
			foreach($matches_img[1] as $ii=>$vv){
				preg_match_all($pattern_src,$vv,$matches_src);
				$img_url = if_url($matches_src[1][0]);
				if($img_url){
					$matches_src_list_jiequ[] = cut_image($img_url);
					$matches_src_list[] = $img_url;
				}
				
		}
	}
	
	
	/**
	 * [cut_image]                  从原图中剪切一部分
	 * @param  [string] $old_imagename [需要剪切的图片名]
	 * @param  [int] $start_width   [从原图片宽为的$start_width开始剪切]
	 * @param  [int] $start_height  [从原图片高为的$start_height开始剪切]
	 * @param  [int] $new_width     [从原图片中剪切$new_width的宽度]
	 * @param  [int] $new_height    [从原图片中剪切$new_height的高度]
	 * @return [null]                [null]
	 */
	#function cut_image($old_imagename,$start_width,$start_height,$new_width,$new_height){
	function cut_image($old_imagename){
		list($old_width,$old_height,$type)=getimagesize($old_imagename);
		
		#算出尺寸
		if($old_width > $old_height){
			$start_width = ($old_width-$old_height)/2;
			$start_height = 0;
			$new_width = $new_height = $old_height;
		}else if($old_height > $old_width){
			$start_height = ($old_height-$old_width)/2;
			$start_width = 0;
			$new_width = $new_height = $old_width;
		}else{
			$start_height = 0;
			$start_width = 0;
			$new_width = $new_height = $old_width;
		}
		
		$types=array(1 => "GIF",2 => "JPEG",3 => "PNG",
			4 => "SWF",5 => "PSD",6 => "BMP",
			7 => "TIFF",8 => "TIFF",9 => "JPC",
			10 => "JP2",11 => "JPX",12 => "JB2",
			13 => "SWC",14 => "IFF",15 => "WBMP",16 => "XBM");
		$type=strtolower($types[$type]);
		$create="imagecreatefrom".$type;
	 
		$old_img=$create($old_imagename);
		$new_img=imagecreatetruecolor($new_width, $new_height);
	 
		imagecopyresampled($new_img,$old_img,0,0,$start_width,$start_height,$new_width,$new_height,$new_width,$new_height);
		$save="image".$type;
	 
		//保存
		$old_imagename_array = explode(".com/",$old_imagename);
		
		$old_imagename_name = strrchr($old_imagename,"/");
		$old_imagename_name = substr($old_imagename_name,1);
		$new_old_imagename_name = "new_".$old_imagename_name;
		$xin_name = str_ireplace($old_imagename_name,$new_old_imagename_name,$old_imagename_array[1]);
		
		#dump($xin_name);die;
		$save($new_img,$xin_name);
		 
		//显示D:/www/music/website/uplode/new_5b0ffb1f8d664.png
	/* 	header("content-type:image/".$type);
		$save($new_img); */
		
		//销毁
		imagedestroy($old_img);
		imagedestroy($new_img);
		return $xin_name;
	}
 
 
	function getcurls(){
		header('content-type:text/html;charset=utf-8');
		$url = "https://api.weixin.qq.com/sns/jscode2session";
        $post_data = array (
		 "blog_url" => "https://api.weixin.qq.com/sns/jscode2session",
		 "appid" => "wxc6cfe9e7f97b9edf",
		 "secret" => "a2dcc0753d8073450c1ca67c4d103cdf",
		 "grant_type" => "authorization_code",
		 "js_code" => "071kE7N02NVkA01GqAN028P0N02kE7Nl"
        );

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        // 设置请求为post类型
        curl_setopt($ch, CURLOPT_POST, 1);
        // 添加post数据到请求中
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

        // 执行post请求，获得回复
        $response= curl_exec($ch);
        curl_close($ch);

        return $response;
	}
	
	
	function getcurl ($url){
			$ch = curl_init();
			curl_setopt ($ch,CURLOPT_URL,$url);
			curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1);
			curl_setopt ($ch,CURLOPT_TIMEOUT,30);
			$content=curl_exec($ch);
			$status=(int)curl_getinfo($ch,CURLINFO_HTTP_CODE );
			if( $status==404)
			{
				return  "";
			}
			curl_close($ch) ;
			return $content;
	}
	
	#查询用户偏好
	function user_style($uid){
		$m_cms_style = M("cms_style");
		$m_mall_content = M("mall_content");
		
		$user_style_map['music_id'] = $uid;
		$user_style_map['style_table'] = 5;     //表示用户
		$user_style_list = $m_cms_style->field('style_id')->where($user_style_map)->select();
		//dump($user_style_list);die;
		$user_style_str = implode(',',array_column($user_style_list,'style_id'));
		if($user_style_str == ''){
			#用户无偏好则推荐所有
			$map['type'] = get_mall_model_conf('MALL_STYLE');
			$map['status'] = 1;
			$list = $m_mall_content->where($map)->order('sort desc')->select();
			$user_style_str = implode(',',array_column($list,'id'));
		}
		return $user_style_str;
	}
	
	/* 按照字段排序 */
	function banner_sorting($arrUsers){
		$sort = array(  
				'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序  
				'field'     => 'sort',       //排序字段  
		);  
		$arrSort = array();  
		foreach($arrUsers AS $uniqid => $row){  
			foreach($row AS $key=>$value){  
				$arrSort[$key][$uniqid] = $value;  
			}  
		}  
		if($sort['direction']){  
			array_multisort($arrSort[$sort['field']], constant($sort['direction']), $arrUsers);  
		}
		return $arrUsers;
	}
	
	#给多图上传添加选择
	function mall_img($type,$form_id,$url){
		$m_mall_content_img = M("mall_content_img");
		$data['uid'] = getUID();
		$data['type'] = $type;
		$data['form_id'] = $form_id;
		$data['url'] = $url;
		$data['time'] = time();
		$data['status'] = 1;
		$m_mall_content_img->add($data);
	}
	
	#多选下拉框判断风格是否存在
	function if_style($style_list,$style_str){
		$style = explode(',',$style_str);
			foreach($style_list as $i=>$v){
				foreach($style as $ii=>$vv){
					if($style_list[$i]['id'] == $style[$ii]){
						$style_list[$i]['if'] = 1;  
					}
				}
			}
		return $style_list;
	}
	
	
	#单曲，专辑 活动  banner 与风格做关联
	#$style_table 1单曲 2专辑 3活动 4banner
	#$music_id   关联id  
	#$style      风格
	function add_style($style_table,$music_id,$style){
		$m_cms_style = M("cms_style");
		#执行删除操作，
		$delete_map['style_table'] = $style_table;
		$delete_map['music_id'] = $music_id;
		$m_cms_style->where($delete_map)->delete();
		
		#执行添加操作
		foreach($style as $i=>$v){
			$add_map['style_table'] = $style_table;
			$add_map['music_id'] = $music_id;
			$add_map['style_id'] = $style[$i];
			$m_cms_style->add($add_map);
		}
	}
 
	#风格id字符串转化为名称字符串
	function style_str($style_array){
		$m_mall_content = M("mall_content");
		$style = explode(',',$style_array);
		
		foreach($style as $ii=>$vv){
			$cmap['id'] = $style[$ii];
			$cdata = $m_mall_content->where($cmap)->find();
			
			$style_name[] = $cdata['name'];
		}
		
		return implode(',',$style_name);
	}
	
	
	
	#所有管理员以及开发者id
	function admin_uid(){
		$m_common_user = M('common_user');
		$map['group_id'] = array('in','1,2');
		$list = $m_common_user->where($map)->field("id")->select();
		$array = array_column($list,'id');
		$id_str = implode(",",$array);
		return $id_str;
	}
	
	
	#查询语言
	function getlangeues(){
		$m_mall_content = M("mall_content");
		$map['type'] = get_mall_model_conf('MALL_LANGUE');
		$map['status'] = 1;
		$langue_list = $m_mall_content->where($map)->order('sort desc')->select();
		return $langue_list;
	}
		
		
	#查询流派风格
	function gettypes(){
		$m_mall_content = M("mall_content");
		$map_t['type'] = get_mall_model_conf('MALL_STYLE');
		$map_t['status'] = 1;
		$style_list = $m_mall_content->where($map_t)->order('sort desc')->field("id,name,img,sort,intro")->select();
		foreach($style_list as $i=>$v){
			$style_list[$i]['img'] = "http://".$_SERVER['HTTP_HOST'].$style_list[$i]['img'];
			$style_list[$i]['intro'] = "http://".$_SERVER['HTTP_HOST'].$style_list[$i]['intro'];
		}
		
		return $style_list;
	}
	
	#状态名称   新专辑状态    二手专辑  1出售中  2可以出售，3已出售
	function status_name($status){
		if($status == 1){
			return "审核通过";
		}else if($status == 2){
			return "草稿";
		}else if($status == 3){
			return "审核中";
		}else if($status == 4){
			return "审核未通过";
		}else if($status == 5){
			return "售罄";
		}
	}
	
	#状态数组
	function getstatus(){
		$status_list = array(array('id'=>1,'name'=>'审核通过'),array('id'=>2,'name'=>'草稿'),array('id'=>3,'name'=>'审核中'),array('id'=>4,'name'=>'审核不通过'));
		return $status_list;
	}
	
	/* 
	*	添加原文件名
	*   $title 新文件名
	*   $original 原文件名
	*   $url 路径
	*   $size 大小
	*/
	function upload_file_name($title,$original,$url,$size){
		$m_common_upload = M("common_upload");
		$data['title'] = $title;
		$data['original'] = $original;
		$data['url'] = trim($url,'.');
		$data['size'] = $size;
		$data['uid'] = getUID();
		$data['type'] = 1;
		$data['time'] = time();
		$data['is_ok'] = 2;
		$data['is_time'] = 0;
		$data['is_uid'] = 0;
		$data['status'] = 1;
		$m_common_upload->add($data);
		
		
	}
	
	/* 文件大小转换 */
	function getFilesize($num){
	   $p = 0;
	   $format='bytes';
	   if($num>0 && $num<1024){
		 $p = 0;
		 return number_format($num).' '.$format;
	   }
	   if($num>=1024 && $num<pow(1024, 2)){
		 $p = 1;
		 $format = 'KB';
	  }
	  if ($num>=pow(1024, 2) && $num<pow(1024, 3)) {
		$p = 2;
		$format = 'MB';
	  }
	  if ($num>=pow(1024, 3) && $num<pow(1024, 4)) {
		$p = 3;
		$format = 'GB';
	  }
	  if ($num>=pow(1024, 4) && $num<pow(1024, 5)) {
		$p = 3;
		$format = 'TB';
	  }
	  $num /= pow(1024, $p);
	  return number_format($num, 3).' '.$format;
	}
	
	
	// Function00056A	
	//发送函数
 	function smsbao_send($phone,$content){
		
		$m_message_conf = M('message_conf');
		$data = $m_message_conf->find(2);
		$value = '【音乐APP】您的验证码为：'."$content";
		$msg = urlencode($value);
		$username = $data['sms_appid'];
		$password = $data['sms_appsecret'];
		
		$url="http://121.42.138.95:8888/sms.aspx?action=send&userid=454&account=$username&password=$password&mobile=$phone&content=$msg";
		
		$status = [
		
			0  =>"发送成功。",
			30 =>"密码错误。",
			40 =>"账号不存在。",
			41 =>"余额不足。",
			42 =>"账号过期。",
			43 =>"IP地址限制。",
			50 =>"内容含有敏感词。",
			51 =>"手机号码不正确。",
			
		];
		
		$ztx_code = [
		
			0  => 6020001,
			30 => 6040003,
			40 => 6040004,
			41 => 6040005,
			42 => 6040006,
			43 => 6040007,
			50 => 6040008,
			51 => 6040009,
			
		];
		
		//$code = file_get_contents($url);
		$code = file_get_contents($url);
		
		//$return_data['status']  = $ztx_code[$code];
		//$return_data['content']['prompt'] = $status[$code];
		
		
		//return $return_data;
		
    }
	// Function00055A	
	function getWeiXinConf(){
		 
		$m_pay_conf = M('pay_conf');
		
	
		$data = $m_pay_conf->find(1);
		
		return $data;
		 
	}
	
	// Function00054A	
	function setPayOrderLog($order_id,$value){
		 
		$m_pay_order_log = M('pay_order_log');
		
		
		$info['order_id'] = $order_id;
		$info['value'] = $value;
		$info['time'] = time();
		$info['ip'] = get_client_ip();
		$info['status'] = 1;
		$m_pay_order_log->add($info);
		 
		 
	}
	
	// Function00053A	
	function getFormName($id){
		 
		$m_research_form = M('research_form');
		 
		 
		 $map['id'] = $id;
		 
		 $data = $m_research_form->where($map)->find();
		 
		 
		 return $data['name'];
		 
		 
		 
	}
	// Function00052A	
	function integralLog($uid,$integral,$type,$value,$status=1,$type_value=1){
		 
		 $m_common_user = M('common_user');
		 $m_mall_integral = M('mall_integral');
		 
		 
		 $map['id'] = $uid;
		 
		 $data = $m_common_user->where($map)->find();
		 
		 
		 $idata['uid'] = $uid;
		 $idata['type'] = $type;
		 $idata['type_value'] = $type_value;
		 $idata['integral'] = $integral;
		 
		 if($type==1){
			 
			 $idata['begin_integral'] = $data['integral'];
			 $idata['end_integral'] = $data['integral']+$integral;
			 $m_common_user->where($map)->setInc('integral',$integral);
		 }else{
			 
			  $idata['begin_integral'] = $data['integral'];
			  $idata['end_integral'] = $data['integral']-$integral;
			  $m_common_user->where($map)->setDec('integral',$integral);
		 }
		 
		 $idata['value'] = $value;
		 $idata['time'] = time();
		 $idata['ip'] = get_client_ip();
		 $idata['status'] = $status;
		 
		 
		 
		 
		 
		 $m_mall_integral->add($idata);
		 
		 
		 
		 
	}
	// Function00051A	
	function isFormAuth($id,$auth){
        
		/*
		$m_research_auth = M('research_auth');
		$m_research_form = M('research_form');
		
		$map['id'] = $id;
		$map['uid'] = getUID();
		
		$result = $m_research_form->where($map)->find();
		//创建者不考虑权限
		if(!$result){
			
			$types = array(
				
				1 =>'create_form',
				2 =>'edit_form',
				3 =>'find_form',
				4 =>'delete_form',
				5 =>'create_field',
				6 =>'edit_field',
				7 =>'find_field',
				8 =>'delete_field',
				9 =>'create_info',
				10 =>'edit_info',
				11 =>'find_info',
				12 =>'delete_info',
				
				
			);
			
			$maps['form_id'] = $id;
			$maps['to_uid'] = getUID();
			$maps[$types[$auth]] = 1;
			
			$results = $m_research_auth->where($maps)->find();
			
			if(!$results){
				
				if(IS_AJAX){
					
					
					
					//返回信息		
					$info = get_errcode(-3);

					echo json_decode($info);
					
				}else{
					
					//$this->error('没有权限');
					redirect('/Research/Form/Manage.html', 3, 'no way');
					
				}
				
				
				die;
			
			}
			
		}	
		*/
        
    }
	// Function00050A	
	 function getFormInfo($id,$list){
        
		
		foreach($list as $i=>$k){
				
			if($list[$i]['field_id']==$id){
				
				$m_research_form = M('research_form');
				
				$data = $m_research_form->find($list[$i]['field_id']);
				
				if($data['input_type']==6){
				
					return "<img style='width:50px;height:50px;' src='".$list[$i]['value']."'>";
				}else{
					return $list[$i]['value'];
				}
			
			}
				
		}
        
    }
	// Function00049A	
	 function get_qr_code($data="",$level='M',$size='6'){
        
		$uid = 2;
		$key = '3b597b7f86a794f9d7fc461def3529f2';
		
        $url="http://qrcode.hongdayun.com/open.php?uid=$uid&key=$key&data=$data&level=$level&size=$size";
        
        $img = file_get_contents($url); 
        
        return $img;
        
    }
	// Function00048A	
	function get_bar_code($data){
	
		$url = "http://barcode.hongdayun.com/html/image.php?filetype=PNG&dpi=72&scale=1&rotation=0&font_family=Arial.ttf&font_size=8&text=$data&thickness=30&checksum=&code=BCGcode39";
		return $url;		
		
	}
	
	// Function00047A	
	function get_url_from_isurl($url){
		
		
	
		 $url="http://isurl.net/create.php?url=$url";
        
        $isurl = file_get_contents($url); 
        
		 $arrResponse=json_decode($isurl,true);
		 
	
		 
		 return $arrResponse['tinyurl'];
		 /** tinyurl */
		
 
	}
	
	// Function00046A	
	function getFormHTML($id){
		
		$m_research_form = M('research_form');
		
		$map['id'] = $id;
	
		$data = $m_research_form->where($map)->find();
		
		//单行
		if($data['input_type']==1){
		
		$html = "
			<div class='form-group'>
				<label for='exampleInputEmail1'>".$data['name']."</label>
				<input name='".$data['id']."' type='test' class='form-control'  placeholder='".$data['value']."'>
			  </div>
			";
		
		//多行
		}else if($data['input_type']==2){
			
			$html = "
			<div class='form-group'>
				<label for='exampleInputEmail1'>".$data['name']."</label>
				<textarea name='".$data['id']."' class='form-control' rows='3' placeholder='".$data['value']."'></textarea>
			 </div>
			";
		
		//单选
		}else if($data['input_type']==3){
			
			$value = explode("|",$data['value']);
			
			$html = "
			<div class='form-group'>
				<label for='exampleInputEmail1'>".$data['name']."</label><br>";
			
			foreach($value as $i=>$k){
				
				if($i==0){
					$info = "
				
					<label class='radio-inline'>
					<input type='radio' name='".$data['id']."'  value='$k'> $k
					</label>
				
					";
					
				}else{
					
					$info = $info."
				
					<label class='radio-inline'>
					<input type='radio' name='".$data['id']."' value='$k'> $k
					</label>
				
					";
				}
				
				
				
				
			}
			
		
			
			$html= $html.$info."</div>";
		
		//多选
		}else if($data['input_type']==4){
			
			$value = explode("|",$data['value']);
			
			$html = "
			<div class='form-group'>
				<label for='exampleInputEmail1'>".$data['name']."</label><br>";
			
			foreach($value as $i=>$k){
				
				if($i==0){
					$info = "
				
					<label class='checkbox-inline'>
					<input type='checkbox' name='".$data['id']."[]'  value='$k'> $k
					</label>
				
					";
					
				}else{
					
					$info = $info."
				
					<label class='checkbox-inline'>
					<input type='checkbox' name='".$data['id']."[]' value='$k'> $k
					</label>
				
					";
				}
				
				
				
				
			}
			
		
			
			$html= $html.$info."</div>";
		
		//描述
		}else if($data['input_type']==5){

			$html = "
			<div class='form-group'>
				<label for='exampleInputEmail1'>".$data['name']."</label>
				<p class='help-block'>".$data['value']."</p>
			  </div>
			";
		
		//文件
		}else if($data['input_type']==6){
			
			
		
			$html = "
			<section>
				<label class='control-label' for='bike_type'>&nbsp;</label>
					<input type='hidden' id='newbikephotoName_".$data['id']."' name='".$data['id']."' value='' />
					<div class='controls' style='text-align:center;'>
						
						<span class='help-inline'></span>
						<br>
						<div id='uploadphotoconfirm_".$data['id']."'></div>
						<br>
						<input type='button' class='btn btn-sm btn-default' style='width:50%' id='upload_button_".$data['id']."'  value='".$data['name']."' /><br/>
						
					</div>
			</section>
		
			
			";
			
		}else if($data['input_type']==7){
			
			
		
			$html = "
			<div class='form-group'>
				<label for='exampleInputEmail1'>".$data['name']."</label>
				<input name='".$data['id']."' type='date' class='form-control'  placeholder='".$data['value']."'>
			  </div>
			";
			
		}else if($data['input_type']==8){
		
		$html = "
		<section class='col col-12'>
					<label class='label' style='color:#666666;'>请选择所在地</label>
					<div class='row' style='margin-left:1px;'>
						<section class='col-xs-4 col-md-4' >
						  <select class='form-control'  id='a_province' name='".$data['id']."[]'></select>
						</section>
						<section class='col-xs-4 col-md-4'>
						 <select class='form-control' id='a_city' name='".$data['id']."[]' ></select>
						</section>
						<section class='col-xs-4 col-md-4'>
						  <select class='form-control' id='a_county' name='".$data['id']."[]'></select>
						</section>
						<script type='text/javascript'>_init_area_a();</script>
					</div>
				</section>
					<br>
				<div class='col-md-12'>
				<div class='form-group'>
					<label for='exampleInputPassword1'>请输入所在地详细地址</label>
					<textarea rows='3'name='".$data['id']."[]' id='review' class='form-control' rows='3' placeholder='请输入所在地详细地址'></textarea>
				  </div>
				</div>
				";
		}
		return $html;
	}
	
	/**
	 * 获得今天时间戳
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>             	 
	 * @return integer 返回今天时间戳  
// Function00045A		 
	 */
	function getUserNicknameByUID($id){
		
		$m_common_user = M('common_user');
		
		$map['id'] = $id;
	
		
		$data = $m_common_user->where($map)->find();
		
		return $data['nickname'];
	};
	
	/* Mall模块公共函数 开始 */
	/**
	 * 获得订单UID
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>             	 
	 * @param integer 订单ID               
	 * @return integer 返回订单UID 
// Function00044A		 
	 */
	function getOrderUID($order_id){
		
		$m_mall_order = M('mall_order');
		
		$map['order_id'] = $order_id;
		$map['form_order_id'] = 0;
		
		$data = $m_mall_order->where($map)->find();
		
		return $data['uid'];
	};
	
	/**
	 * 获得用户OpenID
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>             	 
	 * @return sting 返回用户openid  
 // Function00043A		 
	 */
	function getUserOpenID(){
		
		$m_common_user = M('common_user');
		
		$map['id'] = getUID();
		
		$data = $m_common_user ->where($map)->find();
		
		return $data['weixin_openid'];
	};
	
	/**
	 * 获得指定用户储值余额
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>             	 
	 * @return integer 返回储值余额 
 // Function00042A		 
	 */
	function getUserIDMoney($uid){
		
		$m_common_user = M('common_user');
		
		$map['id'] = $uid;
		
		$data = $m_common_user ->where($map)->find();
		
		return $data['money'];
	};
	
	/**
	 * 获得指定用户储值余额
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>             	 
	 * @return integer 返回储值余额
  // Function00041A		 
	 */
	function getUIDMoney($uid){
		
		$m_common_user = M('common_user');
		
		$map['id'] = $uid;
		
		$data = $m_common_user ->where($map)->find();
		
		return $data['money'];
	};
	
	/**
	 * 获得指定用户储值余额
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>             	 
	 * @return integer 返回储值余额
  // Function00040A	 
	 */
	function getUserMoney(){
		
		$m_common_user = M('common_user');
		
		$map['id'] = getUID();
		
		$data = $m_common_user ->where($map)->find();
		
		return $data['money'];
	};
	
	
	/**
	 * 获得指定用户积分余额
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>             	 
	 * @return integer 积分余额 
  // Function00039A	 
	 */
	function getUIDIntegral($uid){
		
		$m_common_user = M('common_user');
		
		$map['id'] = $uid;
		
		$data = $m_common_user->where($map)->find();
		
		return $data['integral'];
	};
	
	/**
	 * 获得指定用户层级
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>             	 
	 * @return integer 用户层级   
  // Function00038A	 
	 */
	function getUIDHierarchy($uid){
		
		$m_common_user = M('common_user');
		
		$map['id'] = $uid;
		
		$data = $m_common_user->where($map)->find();
		
		return $data['hierarchy'];
	};
	
	
	
	
	/**
	 * 获得上级ID
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>             	 
	 * @return integer 上级ID   
  // Function00037A	 
	 */
	function getPartnerID(){
		
		$m_common_user = M('common_user');
		$map['id'] = getUID();
		
		$data = $m_common_user->where($map)->find();
		
		return $data['superior'];
	};
	/**
	 * 获得今天时间戳
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>             	 
	 * @return integer 返回今天时间戳
  // Function00036A	 
	 */
	function getToday(){
		
		//基础时间
		$baseTime = date('Y-m-d',time());
		//基础三天
		$basetoday = strtotime($baseTime);
		
		
		return $basetoday;
	};
	
	/**
	 * 追加草稿
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param array $name 项目名称
	 * @param string $type 类型 
	 * @param string $for_id 所属上级 
	 * @param string $property 公共还是私有的 
	 * @return array 返回树状数组
	   // Function00035A
	 */
	function set_mall_draft($id){
		
		$m_mall_content = M('mall_content');
		
		$map['id'] = $id;
		
		$data = $m_mall_content->where($map)->find();
		
		unset($data['id']);
		
		$data['form_id'] = $id;
		$data['type'] = get_mall_model_conf('MALL_DRAFT');
		
		$m_mall_content->add($data);
		
	}
	
	
	/**
	 * 获得cms模型配置
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param array $name 项目名称
	 * @param string $type 类型 
	 * @param string $for_id 所属上级 
	 * @param string $property 公共还是私有的 
	 * @return array 返回树状数组
	   // Function00034A
	 */
	function get_mall_order_conf($conf){
		
		$m_mall_content = M('mall_content');
		
		$map['name'] = $conf;
		$map['type'] = get_mall_model_conf('MALL_CONF');
		$map['status'] = 1;
		
		$data = $m_mall_content->where($map)->find();
		
		return $data['value'];
		
	}
	
	/**
	 * 获得cms模型配置
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param array $name 项目名称
	 * @param string $type 类型 
	 * @param string $for_id 所属上级 
	 * @param string $property 公共还是私有的 
	 * @return array 返回树状数组
	  // Function00033A
	 */
	function get_mall_model_conf($model){
		
		$m_mall_content = M('mall_content');
		
		$map['name'] = $model;
		$map['type'] = 1;
		$map['status'] = 1;
		
		$data = $m_mall_content->where($map)->find();
		
		return $data['sort'];
		
	}
	
	
	/**
	 * 获得cms模型配置
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param array $name 项目名称
	 * @param string $type 类型 
	 * @param string $for_id 所属上级 
	 * @param string $property 公共还是私有的 
	 * @return array 返回树状数组
	  // Function00032A
	 */
	function set_mall_model_ok($model,$value){
		
		$m_mall_content = M('mall_content');
		
		$mmap['name'] = $model;
		$mmap['type'] = get_mall_model_conf('CMS_MODEL');
		$mmap['status'] = 1;
		
		$mdata = $m_mall_content->where($mmap)->find();
		
		if($mdata){
			
			return false;
		}
		
		$vmap['sort'] = $value;
		$vmap['type'] = get_mall_model_conf('MALL_MODEL');
		$vmap['status'] = 1;
		
		$vdata = $m_mall_content->where($vmap)->find();
		
		if($vdata){
			
			return false;
		}
		
		return true;
		
		
	}
	
	
	
	
	
	/**
	 * 调用Common中Public控制器
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @return assign 赋值页面 
 // Function00031A	 
	 */
	function common_public(){
		
		return new \Common\Controller\PublicController();
		
	}
	
	/**
	 * 调用Common中Admin控制器
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @return assign 赋值页面  
	 // Function00030A
	 */
	function common_admin(){
		
		return new \Common\Controller\AdminController();
		
	}

	/**
	 * 加密函数
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param   $data 加密内容        
	 * @param   $key  加密钥匙        
	 * @param  string 返回加密内容  
// Function00029A	 
	 */
	function encrypt($data, $key){ 
		$char = '';
		$str = "";
		$key    =   md5($key);
		$x      =   0;
		$len    =   strlen($data);
		$l      =   strlen($key);
		for ($i = 0; $i < $len; $i++)
		{
			if ($x == $l) 
			{
				$x = 0;
			}
			$char .= $key{$x};
			$x++;
		}
		for ($i = 0; $i < $len; $i++)
		{
			$str .= chr(ord($data{$i}) + (ord($char{$i})) % 256);
		}
		return base64_encode($str);
	}

	/**
	 * 解密函数
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param   $data 解密内容        
	 * @param   $key  解密钥匙        
	 * @param  string 返回加密内容
// Function00028A	 
	 */
	function decrypt($data, $key){
		$char = '';
		$str = "";
		$key = md5($key);
		$x = 0;
		$data = base64_decode($data);
		$len = strlen($data);
		$l = strlen($key);
		for ($i = 0; $i < $len; $i++)
		{
			if ($x == $l) 
			{
				$x = 0;
			}
			$char .= substr($key, $x, 1);
			$x++;
		}
		for ($i = 0; $i < $len; $i++)
		{
			if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1)))
			{
				$str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
			}
			else
			{
				$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
			}
		}
		return $str;
	}
	
	 /**
	 * 统一授权登录接口
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param intval $uid  页面标题 
	 * @return cookie session 返回授权信息 
	// Function00027A	 
	 */
	function auth_login($uid,$password){
		
		$m_common_conf = M('common_conf');
		
		//获得需要生成的类型
		$type = $m_common_conf->where('id=2')->getField('value');
		
		if($type==1){
			
			$auth = encrypt($uid,'cookie');
			
			return cookie('auth',$auth,3600*24); 
						
		}else if($type==2){
			
			$auth = encrypt($uid,'session');
			
			return session('auth',$auth); 
			
		}
		
	}
	
	 // /**
	 // * 统一授权登录接口
	 // * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 // * @param intval $uid  页面标题 
	 // * @return cookie session 返回授权信息  
	 // Function00026A
	 // */
	// function is_login($uid){
		
		// $m_common_conf = M('common_conf');
		
		// //获得需要生成的类型
		// $type = $m_common_conf->where('id=2')->getField('value');
		
		// if($type==1){
			
			// $auth = encrypt($uid,$password.'cookie');
			
			// return cookie('auth',$auth,3600*24); 
						
		// }else if($type==2){
			
			// $auth = encrypt($uid,$password.'session');
			
			// return session('auth',$auth); 
			
		// }
		
	// }
		/**
	 * 追加草稿
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param array $name 项目名称
	 * @param string $type 类型 
	 * @param string $for_id 所属上级 
	 * @param string $property 公共还是私有的 
	 * @return array 返回树状数组
	 // Function00025A
	 */
	function set_cms_draft($id){
		
		$m_cms_content = M('cms_content');
		
		$map['id'] = $id;
		
		$data = $m_cms_content->where($map)->find();
		
		unset($data['id']);
		
		$data['form_id'] = $id;
		$data['type'] = get_cms_model_conf('CMS_DRAFT');
		
		$m_cms_content->add($data);
		
	}
	
	
	/**
	 * 获得cms模型配置
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param array $name 项目名称
	 * @param string $type 类型 
	 * @param string $for_id 所属上级 
	 * @param string $property 公共还是私有的 
	 * @return array 返回树状数组
	 // Function00024A
	 */
	function get_cms_model_conf($model){
		
		$m_cms_content = M('cms_content');
		
		$map['name'] = $model;
		$map['type'] = 1;
		$map['status'] = 1;
		
		$data = $m_cms_content->where($map)->find();
		
		return $data['sort'];
		
	}
	
	
	/**
	 * 获得cms模型配置
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param array $name 项目名称
	 * @param string $type 类型 
	 * @param string $for_id 所属上级 
	 * @param string $property 公共还是私有的 
	 * @return array 返回树状数组
	 // Function00023A
	 */
	function set_cms_model_ok($model,$value){
		
		$m_cms_content = M('cms_content');
		
		$mmap['name'] = $model;
		$mmap['type'] = get_cms_model_conf('CMS_MODEL');
		$mmap['status'] = 1;
		
		$mdata = $m_cms_content->where($mmap)->find();
		
		if($mdata){
			
			return false;
		}
		
		$vmap['sort'] = $value;
		$vmap['type'] = get_cms_model_conf('CMS_MODEL');
		$vmap['status'] = 1;
		
		$vdata = $m_cms_content->where($vmap)->find();
		
		if($vdata){
			
			return false;
		}
		
		return true;
		
		
	}
	
	/**
	 * 获取树状类型
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param array $ar 请求的网址 
	 * @param string $id 默认 id  当前对比的标识  
	 * @param string $pid 默认 pid 所属上级的标识  
	 * @return array 返回树状数组
	  // Function00022A
	 */
    function find_child($ar, $id='id', $pid='fmid'){
        foreach($ar as $v) $t[$v[$id]] = $v;

        foreach ($t as $k => $item){
            if( $item[$pid] ) {
                $t[$item[$pid]]['child'][$item[$id]] =& $t[$k];
                $t[$k]['reference'] = true;
            }
        }
        return $t;
    }
	
	/**
	 * 递归去除树状重复类型
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param array $list 请求的网址 
	 * @param string $p_id  所属上级的标识  
	 * @return array 返回树状数组
	  // Function00021A
	 */
	function _findChildren($list,$p_id){   
		 //数据层级化，
          $r = array();
          foreach($list as $id=>$item){
            if($item['fmid'] == $p_id) {
                   $length = count($r);
                  $r[$length] = $item;
                  if($t = _findChildren($list, $item['id']) ){
                      $r[$length]['children'] = $t;
                  }                
            }
          }
          return $r;
    } 
	
	/**
	 * 获得目录
	  // Function00020A
	 */
	function getDir($dir) {
		$dirArray[]=NULL;
		if (false != ($handle = opendir ( $dir ))) {
			$i=0;
			while ( false !== ($file = readdir ( $handle )) ) {
				//去掉"“.”、“..”以及带“.xxx”后缀的文件
				if ($file != "." && $file != "..") {
					$dirArray[$i]=$file;
					$i++;
				}
			}
			//关闭句柄
			closedir ( $handle );
		}
		return $dirArray;
	}

	/**
	 * 获取文件列表
	 // Function00019A
	 */
	function getFile($dir) {
		$fileArray[]=NULL;
		if (false != ($handle = opendir ( $dir ))) {
			$i=0;
			while ( false !== ($file = readdir ( $handle )) ) {
				//去掉"“.”、“..”以及带“.xxx”后缀的文件
				if ($file != "." && $file != ".."&&strpos($file,".")) {
					$fileArray[$i]=$file;
					if($i==100){
						break;
					}
					$i++;
				}
			}
			//关闭句柄
			closedir ( $handle );
		}
		return $fileArray;
	}
	
	/**
	 * 下载文件
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param  string $file_name 文件名                 	 
	 * @param  string $file_dir 文件目录 
	// Function00018A	 
	 */
	 function getFileDownload($file_name,$file_dir) {
		
		if (!file_exists($file_dir.$file_name)){ 
			
			//检查文件是否存在  
		  echo   "文件找不到";  
		  exit;   
		  
		}else{  
		
			$file = fopen($file_dir . $file_name,"r"); // 打开文件
			// 输入文件标签
			Header("Content-type: application/octet-stream");
			Header("Accept-Ranges: bytes");
			Header("Accept-Length: ".filesize($file_dir . $file_name)); //不考虑文件大小 否则会进入死循环
			Header("Content-Disposition: attachment; filename=" . $file_name);
			// 输出文件内容
			echo fread($file,filesize($file_dir . $file_name));
			fclose($file);
		

		}
	 }
	 
	/**
	 * 格式化字节大小
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param  number $size      字节数
	 * @param  string $delimiter 数字和单位分隔符
	 * @return string            格式化后的带单位的大小
	 // Function00017A
	 */
	function format_bytes($size, $delimiter = ''){
		$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
		for ($i = 0; $size >= 1024 && $i < 5; $i++) $size /= 1024;
		return round($size, 2) . $delimiter . $units[$i];
	}
	
	/**
	 * 记录用户日志
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param string $sole 标示 
	 * @return uid 返回UID
	 // Function00016A
	 */
	function action_log($sole){
		
		//判断是否开启日志记录
		$is = getC('ACTION_LOG');
		
		if($is['value']==1){
		
			$m_common_user_behavior = M('common_user_behavior');
			
			$map['sole'] = $sole;
			
			$bdata = $m_common_user_behavior->where($map)->find();
			
			$bid = $bdata?$bdata['id']:0;
			
			$m_common_user_behavior_log = M('common_user_behavior_log');
			
			$uid = getUID()?getUID():0;
			$i = I('')?I(''):'';
			
			$data['uid'] = $uid;
			$data['bid'] = $bid;
			$data['sole'] = $sole;
			$data['i'] = serialize($i);
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$data['status'] = 1;
			
			$m_common_user_behavior_log->add($data);
		}
	} 
	
	
	
	
	
	
	/**
	 * 生成文件夹
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param string $dir 请求的网址 
	 * @param integer $mode 默认 0777 最高权限  
	 * @return fucntion 返回自身  
	 // Function00015A
	 */
	function mkdirs($dir, $mode = 0777){
		
		if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE;
		if (!mkdirs(dirname($dir), $mode)) return FALSE;
		
		return @mkdir($dir, $mode);
		
	} 
	
	/**
	 * getReturnCode($code);
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @return info 获得返回代码  
	 // Function00014A
	 */
	function get_errcode($code){
		
		$m_common_code = M('common_code');
		
		$map['code'] = $code;
		$data = $m_common_code->where($map)->find();
		
		
		$codes['errcode'] = $data['code'];
		$codes['errmsg'] = $data['value'];
			
		return $codes;
		
		
	}
	
	/**
	 * 获得我的菜单
	  // Function00013A
	 */
    function getWebsiteURL(){
        
		return $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
		

    }
	
	/**
	 * 获得我的菜单
	  // Function00012A
	 */
    function getMyNav(){
        
		$m_common_user = M('common_user');
		
		$map['id'] = getUID();
		$data = $m_common_user->where($map)->find();
		
		
		if($data['auth_type']==2){
			
			return unserialize($data['auth']);
			
		}else{
			
			$gdata = getMyAdminGroup(getUID());
		
			return unserialize($gdata['auth']);
		}
		

    }
	
	/**
	 * 获得我所在群组菜单
	 // Function00011B
	 */
    function getMyAdminGroup($id){
        
		$m_common_user = M('common_user');
		$m_common_user_group = M('common_user_group');
		
		$map['id'] = $id;
	
		
		$udata = $m_common_user->where($map)->find();
		
		$ugmap['id']  = $udata['group_id'];
		
		$ugdata = $m_common_user_group->where($ugmap)->find();
		
		return $ugdata;
			
		
    }
	
	/* 获得导航状态 横导航 竖着导航 */
	// Function00010A
	function getNavNID(){
		
		//生成菜单
		$m_common_menu = M('common_menu');

		$url = MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
		
		$map['url'] = array('like',"$url%");
		
		$data = $m_common_menu->where($map)->find();
		
		
		if($data['tier']==1){
			
			$nav_id['across'] = $data['id'];
			$nav_id['vertical'] = 0;
			$nav_id['operation'] =  0;
			
		}else if($data['tier']==2){
			
			$nav_id['across'] = $data['fmid'];
			$nav_id['vertical'] = $data['id'];
			$nav_id['operation'] =  0;
			
			
			
		}else if($data['tier']==3){
			
			$info = getNavByNID($data['fmid']);
			
			$nav_id['across'] = $info['fmid'];
			$nav_id['vertical'] = $data['fmid'];
			$nav_id['operation'] =  $data['id'];
			
		}
		
		return $nav_id;
			
		
	}
	
	/* 获得导航信息 */
	// Function00009A
	function getNavByNID($id){
		
		//生成菜单
		$m_common_menu = M('common_menu');

		$map['id'] = $id;
		
		$data = $m_common_menu->where($map)->find();
		
		return $data;
		
	}
	
	/**
	 * 获得用户getUserInfo
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @return data 返回用户信息
	 * Function00008A
	 */
	function getUserInfo(){
		
		$m_common_user = M('common_user');
		
		$map['id'] = getUID();
		
		$data = $m_common_user->where($map)->find();
		
		return $data;
	} 
	
	/**
	 * 获得我所在群组菜单
	 * Function00007A
	 */
    function getLoginURL($uid){
        
		$m_common_user = M('common_user');
		$m_common_user_group = M('common_user_group');

		$map['id'] = $uid;

		$udata = $m_common_user->where($map)->find();
		
		$map_group['id']  = $udata['group_id'];
		
		$group_data = $m_common_user_group->where($map_group)->find();
		
		return $group_data;
			
		
    }
	
	 /**
	 * 统一授权登录接口
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param intval $uid  页面标题 
	 * @return cookie session 返回授权信息 
	 * Function00006A	 
	 */
	function is_login(){
		
	
		//获得需要生成的类型
		$type = getC('LOGIN_AUTH_TYPE');
		
		if($type['value']==1 and $_COOKIE['uid']==null){
			
			
			redirect(U('Admin/Public/Login'), 0, '登录超时,请重新登录。');
			
						
		}else if($type['value']==2 and $_SESSION['uid']==null){
			
		
			redirect(U('Admin/Public/Login'), 0, '登录超时,请重新登录。');
			
			
		}

	}
	
	/**
	 * 获得用户UID
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @return uid 返回UID
	  * Function00005A
	 */
	function getUID(){
		
		$uid = $_COOKIE['uid'];
		$token = $_COOKIE['token'];
		
		$uid = decode($uid,$token);
		
		return $uid;
		
	} 
	
	/**
	 * 获得Token
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param string $conf 配置 
	 * @param integer $type 1单数据 2是多数据  
	 * @return fucntion 返回自身  
	 * Function00004A
	 */
	function getToken(){
		
		
		return md5(time());
		
		
	} 
	
	/**
	 * 获得配置值
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 * @param string $conf 配置 
	 * @param integer $type 1单数据 2是多数据  
	 * @return fucntion 返回自身  
	 * Function00004A
	 */
	function getC($conf,$type=1){
		
		
		$m_common_conf = M('common_conf');
		
		$map['name'] = $conf;
		
		$data = $m_common_conf->where($map)->find();
		
		if($type==1){
			
			return $data;
		
			
		}else if($type==2){
			
			$map_fcid['fcid'] = $data['id'];
			
			$list = $m_common_conf->where($map_fcid)->order('sort desc,id desc')->select();
			
			return $list;
			
		}
		
		
		
	} 
	
	/**
	 * 简单对称加密算法之加密
	 * Function00003A
	 */
	function login($uid) {
		
		//获得需要生成的类型
		$type = getC('LOGIN_AUTH_TYPE');
		
		//获得密钥
		$token = getToken();
		$uid = encode($uid,$token);
		
		//cookie登录
		if($type['value']==1){
			
			$time = getC('LOGIN_AUTH_TIME');
			
			cookie('uid',$uid,$time['value']); 
			cookie('token',$token,$time['value']); 
		
		//session登录
		}else if($type['value']==2){
			
			session('uid',$uid); 
			session('token',$token); 
			
		}
		
		
	}
	
	/**
	 * 简单对称加密算法之加密
	 * Function00002A
	 */
	function encode($string = '', $skey = 'yiphp') {
		$strArr = str_split(base64_encode($string));
		$strCount = count($strArr);
		foreach (str_split($skey) as $key => $value)
			$key < $strCount && $strArr[$key].=$value;
		return str_replace(array('=', '+', '/'), array('O0O0O', 'o000o', 'oo00o'), join('', $strArr));
	}

	/**
	 * 简单对称加密算法之解密
	 * Function00001A
	 */
	function decode($string = '', $skey = 'yiphp') {
		$strArr = str_split(str_replace(array('O0O0O', 'o000o', 'oo00o'), array('=', '+', '/'), $string), 2);
		$strCount = count($strArr);
		foreach (str_split($skey) as $key => $value)
			$key <= $strCount  && isset($strArr[$key]) && $strArr[$key][1] === $value && $strArr[$key] = $strArr[$key][0];
		return base64_decode(join('', $strArr));
	}

	
	
	
	
	//[ 整理 ]
	
	
	
